<!-- 填报生产订单-生产试验感知-原材料、组部件检测-新增or修改 -->
<template>
  <el-dialog :title="title" :visible.sync="open" width="60%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-tabs v-model="activeName" class="detail-tab" type="card">
        <el-tab-pane label="基本信息" name="first">
          <el-row :gutter="20">
            <!-- <el-col :span="12">
              <el-form-item label="物资种类" prop="type">
                <el-select style="width: 100%;" placeholder="请选择物资种类" v-model="form.type">
                  <el-option :key="dict.value" :label="dict.label" :value="dict.value"
                    v-for="dict in typeOptions"></el-option>
                </el-select>
              </el-form-item>
            </el-col> -->
            <el-col :span="12">
              <el-form-item label="原材料编号" prop="num">
                <el-input v-model="form.num" placeholder="请输入原材料编号" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="原材料名称" prop="name">
                <el-input v-model="form.name" placeholder="请输入原材料名称" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="原材料类型" prop="type">
                <el-input v-model="form.type" placeholder="请输入原材料类型" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="原材料批次号" prop="batch">
                <el-input v-model="form.batch" placeholder="请输入原材料批次号" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="品牌" prop="brand">
                <el-input v-model="form.brand" placeholder="请输入品牌" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="计量单位" prop="unit">
                <el-input v-model="form.unit" placeholder="请输入计量单位" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
  export default {
    data() {
      return {
        // 遮罩层
        loading: true,
        activeName: "first",
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 表单参数
        form: {},
        // 表单校验
        rules: {},
        url: {
          getById: '/goodsFundBack/goodsFundBack/',
          add: '/goodsFundBack/goodsFundBack/add',
          edit: '/goodsFundBack/goodsFundBack/edit',
        }
      }
    },
    methods: {
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          num: null,
          name: null,
          type: null,
          batch: null,
          brand: null,
          unit: null
        };
        this.resetForm("form");
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加原材料检测";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids;
        this.form = row
        this.open = true;
        this.title = "修改原材料检测";
        // getById(this.url.getById, id).then(response => {
        //   this.form = response.data;
        //   this.open = true;
        //   this.title = "修改物料信息";
        // });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.$emit('ok');
              // updateAction(this.url.edit, this.form).then(response => {
              //   this.$modal.msgSuccess("修改成功");
              //   this.open = false;
              //   this.$emit('ok');
              // });
            } else {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.$emit('ok');
              // addAction(this.url.add, this.form).then(response => {
              //   this.$modal.msgSuccess("新增成功");
              //   this.open = false;
              //   this.$emit('ok');
              // });
            }
          }
        });
      },
    }
  }
</script>
